package com.sunzm.droolsdemo;

import org.apache.commons.io.FileUtils;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.utils.KieHelper;

import java.io.File;

public class DroolsDemo2 {
    public static void main(String[] args) throws Exception {
        KieHelper kieHelper = new KieHelper();

        String path = Thread.currentThread().getContextClassLoader().getResource("./").getPath();

        String drlFilePath = path + "rules/test.drl";
        String ruleStr = FileUtils.readFileToString(new File(drlFilePath), "UTF-8");

        //System.out.println("规则: " + ruleStr);
        kieHelper.addContent(ruleStr, ResourceType.DRL);
        KieSession kieSession = kieHelper.build().newKieSession();

        Applicant applicant = new Applicant("康康", 16);
        kieSession.insert(applicant);
        kieSession.fireAllRules();

        kieSession.dispose();
    }
}
